package com.thinkgem.jeesite.modules.wechat.custom;

import com.github.sd4324530.fastweixin.api.MenuAPI;
import com.github.sd4324530.fastweixin.api.config.ApiConfig;
import com.github.sd4324530.fastweixin.api.entity.Menu;
import com.github.sd4324530.fastweixin.api.enums.ResultType;
import com.github.sd4324530.fastweixin.api.response.BaseResponse;
import com.github.sd4324530.fastweixin.util.BeanUtil;

public class MyMenuAPI extends MenuAPI {

	public MyMenuAPI(ApiConfig config) {
		super(config);
	}
	/**
     * 创建菜单
     * 1.3.7开始支持个性化菜单
     *
     * @param menu 菜单对象
     * @return 调用结果
     */
    public ResultType createMenu(Menu menu) {
        BeanUtil.requireNonNull(menu, "menu is null");
        String url = BASE_API_URL;
        if (BeanUtil.isNull(menu.getMatchrule())) {
            //普通菜单
            url += "cgi-bin/menu/create?access_token=#";
        } else {
            //个性化菜单
            url += "cgi-bin/menu/addconditional?access_token=#";
        }
        BaseResponse response = executePost(url, menu.toJsonString().toLowerCase());
        return ResultType.get(response.getErrcode());
    }
}
